// api.js

const BASE_URL = 'http://openapi.keyboardadmin.com:10003'; // 替换成你的接口基础地址

function request(url, method, data = {}) {
  return new Promise((resolve, reject) => {
    dd.httpRequest({
      url: BASE_URL + url,
      method,
      data,
      dataType: 'json',
      success: res => {
        if (res.statusCode === 200) {
          resolve(res.data);
        } else {
          reject(new Error(`请求失败，状态码：${res.statusCode}`));
        }
      },
      fail: err => {
        reject(err);
      },
    });
  });
}

// 导出接口请求方法
export const getExampleData = () => request('/example', 'GET');
export const postExampleData = data => request('/example', 'POST', data);
